package com.yan_jiu_sheng.daily.AC;

import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;

/**
 * https://leetcode.cn/problems/maximum-points-inside-the-square/description/?envType=daily-question&envId=2024-08-03
 * 自我AC通过   排序、遍历check
 * 官方题解：https://leetcode.cn/problems/maximum-points-inside-the-square/solutions/2862469/zheng-fang-xing-zhong-de-zui-duo-dian-sh-qd5w
 *
 * @author yulongtian
 * @create 2024-08-03 9:56
 */
public class Test20240803 {
    public static void main(String[] args) {
//        int[][] points = {{2, 2}, {-1, -2}, {-4, 4}, {-3, 1}, {3, -3}};
        int[][] points = {{1, -1}};
        String s = "a";
        System.out.println(new Test20240803().maxPointsInsideSquare(points, s));
    }

    public int maxPointsInsideSquare(int[][] points, String s) {
        int[][] myPoints = new int[points.length][3];
        for (int i = 0; i < points.length; i++) {
            myPoints[i][0] = points[i][0];
            myPoints[i][1] = points[i][1];
            myPoints[i][2] = s.charAt(i);
        }

        Arrays.sort(myPoints, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return Math.max(Math.abs(o1[0]), Math.abs(o1[1])) - Math.max(Math.abs(o2[0]), Math.abs(o2[1]));
            }
        });
        int ans = 0;
        HashSet<Character> set = new HashSet<>();
        for (int i = 0; i < myPoints.length; i++) {
            int squareLen = Math.max(Math.abs(myPoints[i][0]), Math.abs(myPoints[i][1]));
//            if (squareLen == 0) {
//                continue;
//            }
            int temp_ans = 0;
            for (int j = i; j < myPoints.length; j++) {
                int squareLen2 = Math.max(Math.abs(myPoints[j][0]), Math.abs(myPoints[j][1]));
                if (squareLen2 <= squareLen) {
//                    char ci = (char) myPoints[i][2];
                    char cj = (char) myPoints[j][2];
                    if (!set.contains(cj)) {
                        set.add(cj);
                        temp_ans++;
                    } else {
                        return ans;
                    }
                } else {
                    i = j - 1;
                    break;
                }
            }
            ans += temp_ans;
        }

        return ans;
    }


}
